package com.ruoyi.web.controller.creditlife;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.creditlife.domain.DoctorAppointment;
import com.ruoyi.creditlife.domain.DoctorSchedule;
import com.ruoyi.creditlife.domain.Hospital;
import com.ruoyi.creditlife.service.IHospitalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 医院数据Controller
 * 
 * @author ddd
 * @date 2025-07-11
 */
@RestController
@RequestMapping("/creditlife/hospital")
public class HospitalController extends BaseController
{
    @Autowired
    private IHospitalService hospitalService;

    @PreAuthorize("@ss.hasPermi('creditlife:hospital')")
    @PutMapping("/cancelAppointment")
    public AjaxResult cancelAppointment(@RequestBody DoctorAppointment doctorAppointment) {
        return success(hospitalService.CancelAppointment(doctorAppointment));
    }

    @PreAuthorize("@ss.hasPermi('creditlife:hospital')")
    @PutMapping("/getAppointmentList")
    public AjaxResult getAppointment() {
        return success(hospitalService.getAppointment());
    }

    @PreAuthorize("@ss.hasPermi('creditlife:hospital')")
    @GetMapping("/{hospitalId}/doctors")
    public AjaxResult getHospitalDoctor(@PathVariable("hospitalId") Long hospitalId) {
        return success(hospitalService.getHospitalDoctor(hospitalId));
    }

    @PreAuthorize("@ss.hasPermi('creditlife:hospital')")
    @GetMapping("/{doctorId}/doctorsSchedule")
    public AjaxResult getDoctorSchedule(@PathVariable("doctorId") Long doctorId) {
        return success(hospitalService.getDoctorSchedule(doctorId));
    }

    @PreAuthorize("@ss.hasPermi('creditlife:hospital')")
    @PutMapping("/appointment")
    public AjaxResult appointmentDoctor(@RequestBody DoctorSchedule doctorSchedule) {
        return success(hospitalService.insertApointment(doctorSchedule));
    }
    /**
     * 查询医院数据列表
     */
    @PreAuthorize("@ss.hasPermi('creditlife:hospital')")
    @GetMapping("/list")
    public TableDataInfo list(Hospital hospital)
    {
        startPage();
        List<Hospital> list = hospitalService.selectHospitalList(hospital);
        return getDataTable(list);
    }

    /**
     * 导出医院数据列表
     */
    @PreAuthorize("@ss.hasPermi('creditlife:hospital')")
    @Log(title = "医院数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Hospital hospital)
    {
        List<Hospital> list = hospitalService.selectHospitalList(hospital);
        ExcelUtil<Hospital> util = new ExcelUtil<Hospital>(Hospital.class);
        util.exportExcel(response, list, "医院数据数据");
    }

    /**
     * 获取医院数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('creditlife:hospital')")
    @GetMapping(value = "/{hospitalId}")
    public AjaxResult getInfo(@PathVariable("hospitalId") Long hospitalId)
    {
        return success(hospitalService.selectHospitalByHospitalId(hospitalId));
    }

    /**
     * 新增医院数据
     */
    @PreAuthorize("@ss.hasPermi('creditlife:hospital')")
    @Log(title = "医院数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Hospital hospital)
    {
        return toAjax(hospitalService.insertHospital(hospital));
    }

    /**
     * 修改医院数据
     */
    @PreAuthorize("@ss.hasPermi('creditlife:hospital')")
    @Log(title = "医院数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Hospital hospital)
    {
        return toAjax(hospitalService.updateHospital(hospital));
    }

    /**
     * 删除医院数据
     */
    @PreAuthorize("@ss.hasPermi('creditlife:hospital')")
    @Log(title = "医院数据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{hospitalIds}")
    public AjaxResult remove(@PathVariable Long[] hospitalIds)
    {
        return toAjax(hospitalService.deleteHospitalByHospitalIds(hospitalIds));
    }
}
